<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/cookie.js"></script>
    <style>
        #createCode {
            user-select: none;
        }

        .right {
            color: green;
            font-size: 12px;
        }

        .error {
            color: red;
            font-size: 12px;
        }
    </style>
</head>

<body>
    <!-- -->
    <div class="box">
        <p>
            <label for="">用户名:</label>
            <input type="text" class="user">
            <span class="user_span"></span>
        </p>
        <p>
            <label for="">密&emsp;码:</label>
            <input type="text" class="pwd">
            <span class="pwd_span"></span>
        </p>
        <p>
            <input class="btn"  type="submit" value="登录">
        </p>
    </div>
</body>
<script>
    var userInp = document.getElementsByClassName("user")[0];
    var userSpan = document.getElementsByClassName("user_span")[0];

    var pwdInp = document.getElementsByClassName("pwd")[0];
    var pwdSpan = document.getElementsByClassName("pwd_span")[0];

    var btn = document.getElementsByClassName("btn")[0];

    // 用户输入的用户名和密码   和 cookie中存储的用户名和密码  做比较
    btn.onclick = function(){
        var user = userInp.value;
        var pwd = pwdInp.value;

        if(user && pwd){
            if(user === getCookie("user")){
                if(pwd === getCookie("pwd")){
                    setCookie("lgc",user,7);
                    location.href = "./index.html";
                }else{
                    alert("账号或密码有误!");
                }
            }else{
                alert("该用户未注册!");
            }
        }else{
            alert("请填入完整信息!")
        }



    }

   

   

</script>

</html>